<extend name="Layout/ins_popup" />
<block name="content">
	<div class="panel panel-default ">
		<div class="panel-heading clearfix">
			<div class="pull-left">
				<h4>选择部门</h4>双击可以添加和删除对应的节点
			</div>
			<div class="pull-right">
				<a  onclick="save();" class="btn btn-sm btn-primary">确定</a>
				<a  onclick="myclose();" class="btn btn-sm btn-default">关闭</a>
			</div>
		</div>
		<div class="panel-body">
			<div class="col-28 pull-left">
				<div class="">
					<b>部门</b>
				</div>
				<div class="popup_tree_menu" >
					<div id="dept" style="width:100%;height:424px;" class="dp dept">
						{$list_dept}
					</div>
				</div>
			</div>
			<div class="col-34 pull-right">
				<div>
					<b style="padding-left: 60px;">已选</b><span id="rc_count"></span>
				</div>
				<div class="clearfix" style="margin-bottom: 15px;">
					<label class="col-4 pull-left text-right" ><a onclick="add_address('rc');" class="btn btn-sm btn-primary"> <i class="fa fa-angle-double-right"></i> </a> </label>
					<div class="col-28 pull-right">
						<div id="rc" style="width:100%;height:424px;overflow:hidden">
							<select size="6" style="height:100%;width:100%;"></select>
						</div>
					</div>
				</div>
			</div>
		</div>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		function save() {
			$("#dept_wrap", parent.document).hide();
			$("#dept_wrap span.address_list", parent.document).html("");

			$("#rc select option").each(function(i) {
				id = $(this).val();
				name = jQuery.trim($(this).text());
				html = conv_inputbox_item(name, id);
				$("#dept_wrap .address_list", parent.document).append(html);
			});

			$("#dept_wrap", parent.document).show();

			myclose();
		}


		$(document).ready(function() {
			$("#dept .tree_menu  a").click(function() {
				$("#dept .tree_menu a").removeClass("active");
				$(this).addClass("active");
				return false;
				//禁止连接生效
			});

			$("#dept .tree_menu  a").dblclick(function() {
				$("#dept .tree_menu a").removeClass("active");
				$(this).addClass("active");
				add_address('rc');
				return false;
				//禁止连接生效
			});

			$("#rc  select").on("dblclick", function() {
				$(this).find("option:selected").remove();
				$("#rc_count").text("(" + $("#rc select option").length + ")");
			});

		});
		//最终确认

		function add_address(name) {
			$dept_id = $("#dept a.active").attr("node");
			$dept_name = $("#dept a.active span").text().trim();

			if ($dept_id == undefined) {
				ui_error("请选择部门");
				return false;
			}
			$text = $dept_name;
			$val = "dept_" + $dept_id;
			if ($("#" + name + " select option[value='" + $val + "']").val() == undefined) {
				$("<option></option>").val($val).text($text).appendTo("#" + name + " select");
				$("#" + name + "_count").text("(" + $("#" + name + " select option").length + ")");
			};
		}

		//-->
	</script>
</block>